package demo2;

import java.util.Arrays;

public class LeetCode1089 {
    public void duplicateZeros(int[] arr) {
        int left = -1, right = 0, n = arr.length;
        for (right = 0; right < n; right++) {
            if (arr[++left] == 0) right++;
        }
        if (right == n + 1) {
            arr[n - 1] = 0;
            right = n - 1;
            left--;
        }
        while (left >= 0) {
            arr[--right] = arr[left];
            if (arr[left--] == 0) arr[--right] = 0;
        }
        System.out.println(Arrays.toString(arr));

    }
}